'''
Created on Apr 23, 2012
TC ID: Ecom_5022
Desc: Kiem thu chuc nang sua thong tin nhom nguoi dung
@author: lavang
'''
import unittest
from HTMLTestRunner import HTMLTestRunner
import time
from Functions.loginPageFunc import login
from Functions.globalFunc import readData, preCondition, endCondition
from Functions.userGroupsFunc import clickOnUserGroups,\
    createUserGroup, isUserGroupCreatedSuccessfully, clickOnLinkUserGroup,\
    ClickOnGroup

username=readData("username")
password=readData("password")
tm_groupName=readData("groupName",index=2)
tm_groupName2=readData("groupName", index=3)
tm_description=' this is description'
tm_key='group1'
tm_maxKey=2
tm_defaultLearnerType=readData("userType")
class Ecom_5022(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5022(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
   
        print "Buoc 2: Click vao User groups"
        clickOnUserGroups(self)
        
        print "Buoc 3: Click vao ten nhom muon thay doi thong tin"
        ClickOnGroup(self,tm_groupName)
        
        print "Buoc 4: Thay doi thong tin nhom"
        createUserGroup(self,tm_groupName2,tm_description,tm_key,tm_maxKey,tm_defaultLearnerType)
    
        print "Buoc 5: Tro ve danh sach User group"
        clickOnLinkUserGroup(self)
         
        print "Buoc 6: Kiem tra viec thay doi thong tin thanh cong"
        self.assertTrue(isUserGroupCreatedSuccessfully(self,tm_groupName2), "Failed!")
        print "Passed: User group duoc sua thong tin thanh cong"
    
    def tearDown(self):
        endCondition(self)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5022)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang sua thong tin nhom nguoi dung'
                    )
    runner.run(suite)